package net.hanjava.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * Similar to ByteArrayInputStream.
 * but internal storage is not byte[] but IByte.
 * @author behumble@hanjava.net
 */
public class BytesInputStream extends InputStream {
	private IBytes bytes;
	private int curPos = -1;

	public BytesInputStream(IBytes bytes) {
		this.bytes = bytes;
	}

	@Override
	public int read() throws IOException {
		if(curPos+1<bytes.getSize()) {
			curPos++;
			return bytes.get(curPos);
		}
		return -1;
	}
}